/*
 * Copyright 2008 Johnny Jian
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.getris.game.color

import static org.junit.Assert.*
import org.junit.Test
import java.awt.Color
import org.junit.Before

class ColorfulContainerTest {

	def container

	@Before void setUp() {
		container = new ColorfulContainer(10, 20, 5)
	}

	@Test void testColorAt() {
		container.setColorAt 9, 19, Color.WHITE
		assertEquals Color.WHITE, container.getColorAt(9, 19)

		container.setColorAt(-1, 0, Color.WHITE)
		assertNull container.getColorAt(-1, 0)

		container.setColorAt 0, -1, Color.WHITE
		assertNull container.getColorAt(0, -1)

		container.setColorAt 10, 20, Color.WHITE
		assertNull container.getColorAt(10, 20)
	}

	@Test void testMoveLine() {
		container.squares[0] = ([false] * 10) as boolean[]
		container.squares[19] = ([true] * 10) as boolean[]
		container.colors[0] = ([Color.BLACK] * 10) as Color[]
		container.colors[19] = ([Color.WHITE] * 10) as Color[]

		container.moveLine 0, 19

		assertArrayEquals(([false] * 10) as Object[], container.squares[19])
		assertArrayEquals(([Color.BLACK] * 10) as Color[], container.colors[19])
	}

	@Test void testMoveLine2() {
		container.squares[19] = ([true] * 10) as boolean[]
		container.colors[19] = ([Color.WHITE] * 10) as Color[]

		container.moveLine(-1, 19)

		assertArrayEquals(([false] * 10) as Object[], container.squares[19])
		assertArrayEquals(([null] * 10) as Color[], container.colors[19])
	}

}
